package xyz.scootaloo.oj

import cn.hutool.core.lang.Console
import org.junit.Test

/**
 * @author flutterdash@qq.com
 * @since 2021/4/29 17:11
 */
class P191 {

    fun hammingWeight(n: Int): Int {
        val base = 1
        var number = n
        var count = 0

        while (number != 0) {
            if (number.and(base) == base)
                count++
            number = number.ushr(1)
        }

        return count
    }

    @Test
    fun test0() {
//        Console.log(hammingWeight(1))
//        Console.log(hammingWeight(2))
//        Console.log(hammingWeight(3))
//        Console.log(hammingWeight(4))
//        Console.log(hammingWeight(Int.MAX_VALUE))
        Console.log(hammingWeight(4294967293.toInt()))
    }

}
